/**
 * 
 */
package com.spaceserviver.misc;

import com.badlogic.gdx.graphics.g2d.TextureRegion;

/**
 * @author kot
 * 
 */
public class ImageCheckbox extends ImageButton {

	private Boolean checked = false;
	private TextureRegion checkedRegion;
	private TextureRegion uncheckedRegion;

	public StateChangeListener stateListener;

	public ImageCheckbox(TextureRegion checked, TextureRegion unchecked) {
		super(checked, unchecked);

		checkedRegion = checked;
		uncheckedRegion = unchecked;
	}

	public void SetState(Boolean checked) {
		this.checked = checked;

		if (checked) {
			super.setRegion(checkedRegion);

		} else {
			super.setRegion(uncheckedRegion);
		}
	}

	public Boolean isChecked() {
		return checked;
	}

	@Override
	public boolean touchDown(float x, float y, int pointer) {

		if (checked) {
			super.setRegion(uncheckedRegion);
			checked = false;
		} else {
			super.setRegion(checkedRegion);
			checked = true;
		}

		if (this.clickListener != null)
			this.clickListener.onClick(this);

		if (this.stateListener != null)
			this.stateListener.onStateChanged(this);

		return false;
	}

	public interface StateChangeListener {
		public void onStateChanged(ImageCheckbox checkbox);
	}

}
